home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.01 Jan 94 / Color Buttons / CDEF.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-16  |  2.3 KB  |  121 lines  |  [TEXT/KAHL]

  1. pascal long main(var,CH,msg,par)
  2. int msg,var;
  3. ControlHandle CH;
  4. long par;
  5. {
  6.     long l;
  7.  
  8.     l=0L;
  9.     switch(msg){
  10.         case 0: 
  11.             doDraw(CH); 
  12.             break;
  13.         case 1: 
  14.             l=(long)doTest(par,CH); 
  15.             break;
  16.         case 2: 
  17.             doCalc(par,CH); 
  18.             break;
  19.     }
  20.     return l;
  21. }
  22.  
  23. doTest(par,CH)
  24. long par;
  25. ControlHandle CH;
  26. {
  27.     Point pt;
  28.  
  29.     pt.v=HiWord(par); 
  30.     pt.h=LoWord(par);
  31.     return (int)PtInRect(pt,&((**CH).contrlRect));
  32. }
  33.  
  34. doCalc(par,CH)
  35. RgnHandle par;
  36. ControlHandle CH;
  37. {
  38.     par=(RgnHandle)((long)par&0x7FFFFFFF);
  39.     RectRgn(par,&((**CH).contrlRect));
  40. }
  41.  
  42. doDraw(CH)
  43. ControlHandle CH;
  44. {
  45.     int j,k,*p;
  46.     Handle tItem;
  47.     Rect r;
  48.     RGBColor rgb,rgb1,rgb2; 
  49.     AuxCtlHandle ax;
  50.     FontInfo inf;
  51.     
  52.     r=(**CH).contrlRect; 
  53.     j=StringWidth((**CH).contrlTitle); 
  54.     GetFontInfo(&inf); 
  55.     k=inf.ascent+inf.descent;
  56.     k=(r.top+r.bottom+k)/2;
  57.     MoveTo((r.left+r.right-j)/2,k-inf.descent);
  58.     DrawString((**CH).contrlTitle);
  59.     GetAuxCtl(CH,&ax);
  60.     
  61.     p=(int *)&(**(**ax).acCTable).ctTable[0].rgb.red;    
  62.     rgb.red=p[0];        /* 21845, 0x5555*/
  63.     rgb.green=p[1];        /* 21845, 0x5555*/
  64.     rgb.blue=p[2];        /* 21845, 0x5555*/
  65.     rgb1.red=p[4];        /* 34952, 0x8888*/
  66.     rgb1.green=p[5];    /* 34952, 0x8888*/
  67.     rgb1.blue=p[6];        /* 34952, 0x8888*/
  68.     rgb2.red=rgb2.green=rgb2.blue=0xFFFF;
  69.     
  70.      PenSize(2,2);
  71.     RGBForeColor(&rgb);
  72.     MoveTo(r.right-2,r.top); 
  73.     LineTo(r.left,r.top);
  74.     LineTo(r.left,r.bottom-2); 
  75.     RGBForeColor(&rgb2);
  76.     MoveTo(r.right-2,r.top+1);
  77.     LineTo(r.right-2,r.bottom-2);
  78.     LineTo(r.left,r.bottom-2); 
  79.     rgb2.red=rgb2.green=rgb2.blue=0;
  80.     RGBForeColor(&rgb2);
  81.     InsetRect(&r,2,2);
  82.     FrameRect(&r);
  83.  
  84.     InsetRect(&r,2,2);
  85.     if(!(**CH).contrlHilite){
  86.         PenSize(1,1);
  87.         RGBForeColor(&rgb);
  88.         MoveTo(r.left,r.top);
  89.         LineTo(r.left,r.bottom-2);
  90.         PenSize(2,2); 
  91.         LineTo(r.right-2,r.bottom-2);
  92.         Move(0,-1);
  93.         PenSize(1,1);
  94.         RGBForeColor(&rgb1);
  95.         LineTo(r.left+1,r.bottom-3);
  96.         LineTo(r.left+1,r.top);
  97.         LineTo(r.right-1,r.top);
  98.         Move(0,1);
  99.         rgb2.red=rgb2.green=rgb2.blue=0xFFFF; 
  100.         RGBForeColor(&rgb2);
  101.         LineTo(r.left+2,r.top+1);
  102.     }
  103.     else {
  104.         MoveTo(r.right-2,r.top);
  105.         RGBForeColor(&rgb);
  106.         LineTo(r.left,r.top);
  107.         PenSize(1,1);
  108.         LineTo(r.left,r.bottom-3);
  109.         PenSize(3,3);
  110.         LineTo(r.right-3,r.bottom-3); 
  111.         PenSize(1,1);
  112.         Move(2,-1);
  113.         RGBForeColor(&rgb1); 
  114.         LineTo(r.left+1,r.bottom-4);
  115.         LineTo(r.left+1,r.top+2);
  116.         LineTo(r.right-1,r.top+2);
  117.     }
  118.     rgb2.red=rgb2.green=rgb2.blue=0;
  119.     RGBForeColor(&rgb2); 
  120. }
  121.